/**
 * @(#)HistoryTaskInstanceVO.java 2009-12-10
 *   
 * Copyright  (c) 2009-2010 Wilmar IT Service,  Inc.   
 * All  rights  reserved.   
 * TODO
 */

package com.wilmar.process.entity.vo;

import java.text.SimpleDateFormat;

import org.jbpm.api.ProcessInstance;
import org.jbpm.api.history.HistoryTask;

import com.wilmar.process.core.ProcessSystemDeclareKeys;
import com.wilmar.process.entity.ProcessLog;

/**
 * @author asus Email:zhoulibo_java@msn.cn
 * @version 1.0.0
 */
public class HistoryTaskInstanceVO extends AbstractValueObject implements
		ValueObject {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 1L;

	private String id;
	private String name;
	private String description;
	private String executionId;
	private String createTime;
	private String endTime;
	private String state;
	private String assignee;
	private String outcome;
	private Long duration;
	private String processInstanceId;
	private String processInstanceKey;

	private boolean revokeAble;

	private String viewUrl;

	public HistoryTaskInstanceVO(HistoryTask historyTask, ProcessInstance pi,
			ProcessLog operateLog, boolean revokeAble, String viewUrl) {
		SimpleDateFormat sdf = new SimpleDateFormat(
				ProcessSystemDeclareKeys.SYSTEM_LONG_DATE_FORMAT
						+ ProcessSystemDeclareKeys.SPACE
						+ ProcessSystemDeclareKeys.SYSTEM_LONG_TIME_FORMAT);
		this.id = historyTask.getId();
		this.executionId = historyTask.getExecutionId();
		this.createTime = sdf.format(historyTask.getCreateTime());
		if (historyTask.getEndTime() != null) {
			this.endTime = sdf.format(historyTask.getEndTime());
		} else {
			this.endTime = "";
		}
		if (pi != null) {
			this.processInstanceId = pi.getId();
			this.processInstanceKey = pi.getKey();
		} else {
			String ids[] = this.executionId.split("\\.");
			this.processInstanceId = ids[0] + "." + ids[1];
			this.processInstanceKey = "";
		}
		this.name = operateLog.getNodeName();
		this.description = operateLog.getNodeDesc();
		this.state = historyTask.getState();
		this.assignee = historyTask.getAssignee();
		this.outcome = historyTask.getOutcome();
		this.duration = historyTask.getDuration();
		this.revokeAble = revokeAble;
		this.viewUrl = viewUrl;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getExecutionId() {
		return executionId;
	}

	public void setExecutionId(String executionId) {
		this.executionId = executionId;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getAssignee() {
		return assignee;
	}

	public void setAssignee(String assignee) {
		this.assignee = assignee;
	}

	public String getOutcome() {
		return outcome;
	}

	public void setOutcome(String outcome) {
		this.outcome = outcome;
	}

	public String getProcessInstanceId() {
		return processInstanceId;
	}

	public void setProcessInstanceId(String processInstanceId) {
		this.processInstanceId = processInstanceId;
	}

	public String getProcessInstanceKey() {
		return processInstanceKey;
	}

	public void setProcessInstanceKey(String processInstanceKey) {
		this.processInstanceKey = processInstanceKey;
	}

	/**
	 * @return the duration
	 */
	public Long getDuration() {
		return duration;
	}

	/**
	 * @param duration
	 *            the duration to set
	 */
	public void setDuration(Long duration) {
		this.duration = duration;
	}

	/**
	 * @return the revokeAble
	 */
	public boolean isRevokeAble() {
		return revokeAble;
	}

	/**
	 * @param revokeAble
	 *            the revokeAble to set
	 */
	public void setRevokeAble(boolean revokeAble) {
		this.revokeAble = revokeAble;
	}

	public String getViewUrl() {
		return viewUrl;
	}

	public void setViewUrl(String viewUrl) {
		this.viewUrl = viewUrl;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		HistoryTaskInstanceVO other = (HistoryTaskInstanceVO) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

}
